﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace CGAL.Grasshopper.Wrapper;

internal partial class UnsafeNativeMethods
{
    private const string DLL_NAME = "CGAL.Native.dll";

    [LibraryImport(DLL_NAME, EntryPoint = nameof(Polygon2D_Create))]
    internal static partial void Polygon2D_Create(
        [MarshalAs(UnmanagedType.LPArray), In] double[] Point2DArray, ulong pointsCount,
        ref IntPtr polygon2D
    );

    [LibraryImport(DLL_NAME, EntryPoint = nameof(StraightSkeleton_Create))]
    internal static partial void StraightSkeleton_Create(
        [MarshalAs(UnmanagedType.LPArray), In] double[] outorPolygon2DArray, ulong OutorPointsCount,
        [MarshalAs(UnmanagedType.LPArray), In] double[] holePolygon2DArray, ulong holePointsCount,
        ref IntPtr StraightSkeletonLineArray, ref IntPtr lineSize
    );

    [LibraryImport(DLL_NAME, EntryPoint = nameof(ExtrudeSkeleton))]
    internal static partial void ExtrudeSkeleton(
        [MarshalAs(UnmanagedType.LPArray), In] double[] polygon2DArray,
        [MarshalAs(UnmanagedType.LPArray), In] ulong[] polygonCountArray,
        ulong polygonCount,
        [MarshalAs(UnmanagedType.LPArray), In] double[] angleArray,
        double maximum_height,
        ref IntPtr meshArray, ref IntPtr faceCount
    );

    [LibraryImport(DLL_NAME, EntryPoint = nameof(ReleaseDoubleArray))]
    internal static partial void ReleaseDoubleArray(IntPtr arr);

    [LibraryImport(DLL_NAME, EntryPoint = nameof(ReleaseInt))]
    internal static partial void ReleaseInt(IntPtr int32);

    [LibraryImport(DLL_NAME, EntryPoint = nameof(ReleaseIntArray))]
    internal static partial void ReleaseIntArray(IntPtr int32);
}
